package entity

import (
	"strconv"
	"time"

	"shqsoft.cn/pasnj/base"
	"shqsoft.cn/pasnj/bi/cube"
)

//HKYW 用户
type HKYW struct {
	JLID                   int        `gorm:"AUTO_INCREMENT;primary_key;column:JLID"`
	Sjrq                   *time.Time `gorm:"column:数据日期;type:date;"`
	Khmc                   string     `gorm:"column:客户名称;size:20"`
	Bz                     string     `gorm:"column:币种;size:60"`
	Jydm                   string     `gorm:"column:交易产品种类代码;size:60"`
	Khdm                   string     `gorm:"column:客户种类代码;size:60"`
	Ywdm                   string     `gorm:"column:业务类型代码;size:60"`
	Glunmbal2              float64    `gorm:"column:当月交易金额"`
	Amtdistcntrmb          float64    `gorm:"column:当月交易笔数"`
	Currbaldiscntrmb       float64    `gorm:"column:当月手续费收入折美"`
	Commfeeincomediscntrmb float64    `gorm:"column:当月手续费收入折人"`
	Currbal2discntrmb      float64    `gorm:"column:当月邮电费收入折美"`
	Marginamtdiscntrmb     float64    `gorm:"column:当月邮电费收入折人"`
	CUID                   int        `gorm:"column:CUID"`
	YG1                    string     `gorm:"-"`
	ZB1                    *float64   `gorm:"-"`
	YG2                    string     `gorm:"-"`
	ZB2                    *float64   `gorm:"-"`
	YG3                    string     `gorm:"-"`
	ZB3                    *float64   `gorm:"-"`
	YG4                    string     `gorm:"-"`
	ZB4                    *float64   `gorm:"-"`
	YG5                    string     `gorm:"-"`
	ZB5                    *float64   `gorm:"-"`
}

//TableName User用户表名
func (HKYW) TableName() string {
	return "V_INDI_HKYW"
}

func (c *HKYW) AfterFind() (err error) {
	var share *cube.Share
	share, err = cube.GetShare("comp_qtzb_divi")
	if err != nil {
		return
	}
	var diviMap map[string]float64
	diviMap, err = share.GetDivision("10:" + strconv.Itoa(c.JLID))
	if err != nil {
		return
	}
	i := 0
	if (diviMap == nil || len(diviMap) == 0) && c.Khdm == "对公" {
		share, err = cube.GetShare("comp_clie_divi")
		if err != nil {
			return
		}
		diviMap, err = share.GetDivision(strconv.Itoa(c.CUID))
		if err != nil {
			return
		}
	}
	if (diviMap == nil || len(diviMap) == 0) && c.Khdm == "对私居民" {
		share, err = cube.GetShare("indi_clie_divi")
		if err != nil {
			return
		}
		diviMap, err = share.GetDivision(strconv.Itoa(c.CUID))
		if err != nil {
			return
		}
	}
	for k, v := range diviMap {
		val := v
		i++
		switch i {
		case 1:
			c.YG1 = k
			c.ZB1 = &val
		case 2:
			c.YG2 = k
			c.ZB2 = &val
		case 3:
			c.YG3 = k
			c.ZB3 = &val
		case 4:
			c.YG4 = k
			c.ZB4 = &val
		case 5:
			c.YG5 = k
			c.ZB5 = &val
		default:
			break
		}
	}
	return
}

// HKYWEF G
func HKYWEF() base.EntityFunc {
	return func() interface{} {
		entity := HKYW{}
		return &entity
	}
}

//HKYWESF GJ
func HKYWESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []HKYW
		return &entities
	}
}
func init() {
	dao := base.NewDefaultDao(HKYWEF(), HKYWESF(), nil)
	filter := base.DefaultFilter{
		FilterColName: "JLID",
		TableName:     "T_COMP_QTZB_DIVI",
		EmidColName:   "emid",
		AcidColName:   "jlid",
		WhereCause:    "ywid=10",
	}
	dao.Fileter = &filter
	base.DaoPoolObj.Put("HKYW", dao)
}
